<template>
    <transition enter-active-class="animate__animated animate__fadeIn" 
    leave-active-class="animate__animated animate__fadeOut"
    >
        <div class="mask" v-if="visible">
            <div class="modal-wrap" key="div">
                <div class="title">
                    <slot name="title">提示</slot>
                </div>
                <div class="body">
                    <slot name="body"> 提示内容</slot>
                </div>
                <div class="footer">
                    <button class="del" @click="$emit('on-cancel')">取消</button>
                    <button class="confirm" @click="$emit('on-confirm')">确定</button>
                </div>
            </div>
        </div>
    </transition>
</template>
<script>

//思考一下为什么要封装这个组件
//我的项目需要封装这个组件来提高复用性,封装一个modal组件,用于弹窗显示
//element已经有了 你为什么还要封装? 我们的页面中 弹窗组件需要添加额外的动画效果 所以需要配合animate.css进行二次封装


//1.控制组件的显示和隐藏,想到使用v-if来控制显示和隐藏,需要接受一个布尔值,visible

//2.一个组件如何能够灵活的展示不同的弹窗内容

//3.点击按钮的时候 需要做什么,变更父组件中传递的visible的值

//设计自定义的事件名 取消按钮触发的事件名:on-cancel 确定按钮触发的事件叫做on-confirm
import "animate.css"
export default {
    props: {
        visible: {
            type: Boolean,
            default() {
                return false
            }
        }
    }
}
</script>
<style scoped>
.mask {
    background-color: rgba(0, 0, 0, .6);
    position: fixed;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-wrap {
    border-radius: 10px;
    background-color: #fff;
    width: 400px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    /* border: 1px solid #ccc; */
}

.mask .title,
.mask .footer,
.mask .body {
    margin: 20px 0
}

button {
    outline: none;
    border: 0;
    width: 100px;
    height: 40px;
    background: linear-gradient(90deg, #1596fb, #002dff);
    border-radius: .28571429rem;
    /* display: block; */

    color: #fff;
    cursor: pointer;
}

.footer {
    width: 100%;
    text-align: center;
}

.footer button {
    margin-left: 20px
}

.del {
    background-image: linear-gradient(90deg, #fb1565, #ff00cc);
}

button:hover {
    background-image: linear-gradient(90deg, #aebaac, #57da23);
}
</style>